package com.xgkj.diyiketang.util.xiangce;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.xgkj.diyiketang.ProtocolConst;
import com.xgkj.diyiketang.activity.BaseActivity;
import com.xgkj.diyiketang.R;

import java.util.ArrayList;

/**
 * Created by windo on 16/4/14.
 */
public class PhoneFolderActivity extends BaseActivity{

    private Context mContext;
    private final String TAG = getClass().getSimpleName();
    private TextView cancel_btn;
    private ListView mList;
    private FolderAdapter mAdapter;
    private ArrayList<PhotoFolderInfo> folderList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.phone_folder);
        mContext = this;
        initView();
    }



    private void initView() {
        Intent intent = getIntent();
        if (intent != null){
            folderList =  intent.getParcelableArrayListExtra(ProtocolConst.FOLDER_LIST);
        }
        cancel_btn = (TextView) findViewById(R.id.cancel_btn);
        cancel_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        mList = (ListView) findViewById(R.id.folder_list);
        mAdapter = new FolderAdapter(mContext);
        mList.setAdapter(mAdapter);
        mAdapter.updateData(folderList);
        mList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                PhotoFolderInfo info = (PhotoFolderInfo) mAdapter.getItem(position);
                Intent intent = new Intent(mContext,PhoneMainActivity.class);
                intent.putExtra(ProtocolConst.IMAGE_LIST,(ArrayList<PhotoImageInfo>)info.imageList);
                intent.putExtra(ProtocolConst.PHOTO_FROM,ProtocolConst.FROM_FOLDER);
                mContext.startActivity(intent);
            }
        });
    }


}
